package LanQiao.Testing;

import java.util.Scanner;

public class Main7 {
    public static boolean gj(long n){
        boolean flag=true;
        while (n>0){

            if (n%10==2){
                flag=false;
                break;
            }else {
                n=n/10;
            }
        }
        return flag;
    }
    public static void main(String[] args) {
        long sum=0;
        Scanner sc=new Scanner(System.in);
        long n=sc.nextInt();
        for (long i=1;i<=n;i++){
            if (gj(i)){
                sum++;
            }
        }
        System.out.println(sum);
    }
}
